const Router = require('koa-router');
const addComment = new Router();
const sqldata = require('./sqldata');

// 添加评论
addComment.post('/comment',async (ctx) => {
    let mydata = await new Promise((resolve, reject)=>{
        let val=ctx.request.body;
        const sqlLang =`INSERT INTO comment ( Wid, Uid, Ctime, Czan, Ctext) VALUES ('${val.Wid}', '${val.Uid}', '${val.Ctime}', '${val.Czan}', '${val.Ctext}')`;
        return sqldata(sqlLang, (err, data)=>{
            if(err) reject(err);
            resolve(data);	// 返回拿到的数据
        })
    })
    ctx.body=mydata;
})
//显示评论
addComment.get('/look', async (ctx)=>{
    //ctx.body = "社区-详情页";
    let mydata = await new Promise((resolve, reject)=>{
        var val=ctx.request.query;
        console.log(val)
        let sqlLang = `select * from comment
        where Wid ='${val.Wid}'`;
        return sqldata(sqlLang, (err, data)=>{
            if(err) reject(err);
            resolve(data);	// 返回拿到的数据
        })
    })
    ctx.body = mydata;
})


module.exports = addComment;